<template>
  <div>
    <Nav :title="title" :back="back"></Nav>
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="username"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="psd"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px;">
        <van-button class="btn" round block type="info" native-type="submit">提交</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import login from "../models/login";
import { Toast } from "vant";
export default {
  data() {
    return {
      title: "用户登录",
      back: "/movieList",
      username: "",
      password: ""
    };
  },
  methods: {
    async onSubmit(values) {
      var data = await login(values.username, values.psd);
      console.log(data);
      if (data.data.res) {
        //登录成功
        Toast.success({
          message: "登录成功！",
          duration:1000,
          onOpened: () => {
            this.$router.push("/center");
          }
        });
      } else {
        Toast.fail(data.data.msg);
      }
    }
  }
};
</script>

<style scoped>
.btn{
  padding: 40px;
  font-size: 30px;
}
</style>